<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>旅游卡激活</title>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
<link rel="stylesheet" href="{{ url('/common/mobile-common/common.css') }}">
<link rel="stylesheet" href="{{ url('/mobile/css/header.css') }}">		
<link rel="stylesheet" href="{{ url('/mobile/css/card/index.css') }}">	
<script src="{{ url('mobile/js/jquery-1.8.3.min.js') }}"></script>
<script src="{{ url('/common/mobile-common/hmt.js') }}"></script>
</head>
<body>
	<div class="abouts">
		<div class="wrap-cont clearfix">
				<!--header-->
				<!--<header>
					<div class="top">
							<img src="{{ url('mobile/images/fh-red.png') }}">
						<p>旅游卡激活</p>
					</div>
				</header>-->
				<!--end-->
				<div class="wrap-cont wrap-cont2">
					<p class="tit-ts">请输入旅游卡的卡号及密码，完成激活。</p>					
					<div class="km kms">
						<label>卡号:</label>
						<p><input type="text" name="card-num" class="card-num" value="请输入卡号" onfocus="{value=''}"></p>
						<label>密码:</label>
						<p class="mmtxt"><input type="text" name="mm-num" class="mm-num" value="请输入密码" onfocus="{value=''}"></p>
						<a><img src="{{ url('mobile/images/sc-icon2.png') }}"></a>
					</div>
				</div>
				<div class="dv-add">
						<a><img src="{{ url('mobile/images/add-img.png') }}"></a>
					</div>
				<div class="wrap-cont wrap-cont3">
					<div class="km">
						<label>手机号:</label>
						<p><input type="text" name="tel-num" class="tel-num" value="请输入手机号" onfocus="{value=''}"></p>
						<label>验证码:</label>
						<p>
							<input type="text" name="yz-num" class="yz-num" value="请输入验证码" onfocus="{value=''}">
							<button class="hqyzm">获取验证码</button>
						</p>						
					</div>				
				</div>
				<div class="jh-btn">
					<a class="a-btn">激活</a>
				</div>
		</div>
	</div>
	
	
</body>
<script>
	$(function(){
		var kmLen=$(".kms").length;
		//添加
		$(".dv-add a").on("touchstart",function(){
			var cardIndex=$(".wrap-cont2 .km.kms").length;
			if(cardIndex>=5){
				alert("最多只能激活5张卡哦！");
			}
			else{
				kmLen++;
				addCard($(".wrap-cont2"));
				$(".kms p input").focus(function(){
					$(this).val('');
				});
			}			

			
		});
		$(".jh-btn .a-btn").on("touchstart",function(){
				yzFun();
		});
		$(".kms a").unbind().on("touchstart",function(){
			--kmLen;
			removCard($(this));
		});

		//删除
		function removCard(i){
			var comTxt=confirm("是否删除此卡信息？");
			if(comTxt){
				i.parent().remove();
			}
			return false;
		}
		function addCard(e){
			var carInfo='';
			carInfo+='<div class="km kms"><label>卡号:</label>';
			carInfo+='<p><input type="text" name="card-num" class="card-num" value="请输入卡号"></p>';
			carInfo+='<label>密码:</label>';
			carInfo+='<p class="mmtxt"><input type="text" name="mm-num" class="mm-num" value="请输入密码"></p>';
			carInfo+='<a><img src="{{ url('mobile/images/sc-icon2.png') }}"></a>';
			carInfo+='</div>';
			$(e).append(carInfo);
			$(".kms a").unbind().on("touchstart",function(){
				--kmLen;
				removCard($(this));
			});
		};
		//验证
		function yzFun(){
			var telNum=$(".tel-num");
			var yzNum=$(".yz-num");
			var myreg = /^1[34578]\d{9}$/;
			var carDv=$(".km.kms");
			var index=0;
			carDv.each(function(){
				++index;
				if($(this).find(".card-num").val()=='' || $(this).find(".card-num").val()=='请输入卡号'){
				alert("卡号不能为空");
				$(this).find(".card-num").focus();
				return false;
				}
				else if($(this).find(".mm-num").val()==''||$(this).find(".mm-num").val()=='请输入密码'){
					alert("请输入密码");
					$(this).find(".mm-num").focus();
					return false;
				}
				if(index==kmLen){
					if(telNum.val()==''||telNum.val()=='请输入手机号'){
						alert("请输入手机号");
						telNum.focus();
					}
					else if(!telNum.val().match(myreg)){
						alert("请输入正确的手机号码");
						telNum.focus();
					}
					else if(yzNum.val()==''||yzNum.val()=='请输入验证码'){
						alert("请输入验证码");
						yzNum.focus();
					}
				}
			});

		};
		//获取验证码
			var telNum=$(".tel-num");
			var yzNum=$(".yz-num");
			var myreg = /^1[34578]\d{9}$/;
			var yztel=false,yztel2=false;
			$(".hqyzm").on("touchstart",function(){
				if(telNum.val()==''||telNum.val()=='请输入手机号'){
					alert("请输入手机号");
					telNum.focus();
					return yztel=true;
				}
				else if(!telNum.val().match(myreg)){
					alert("请输入正确的手机号码");
					telNum.focus();
					return yztel2=true;
				}
				else{
					settim();
				}
		});
		
		//验证码发送倒计时
		 var wait = 60;
         var isSend = false;
         function settim() {
         if (wait == 0) {
//          $(".hqyzm").attr("onclick", "sendSecurityCode()");
            $(".hqyzm").text("重新获取验证码");
            wait = 60;
            return false;
          } else {
          	
            $(".hqyzm").text("" + wait + "s");
            $(".hqyzm").attr("disabled",true);
            $(".hqyzm").attr("onclick", "");
            wait--;
            //编辑器
            setTimeout(function () {
                settim();
            }, 1000)
        }
    	};
	})
</script>
</html>
